/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.webmarmun;

/**
 *
 * @author sasa
 */
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.Size2DSyntax;
import javax.print.attribute.standard.Copies;
import javax.print.attribute.standard.MediaSize;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableRowSorter;

public class TableFromDatabase extends javax.swing.JFrame {

    private String sveZajedno;
    private String str_date;
    public static String SU;
    public static String DATUM;
    public static String POROTNIK;
    public static String SUDIJA;
    public static String MESTO;
    public static Float RADNISAT;
    public static int BROJSATI;
    public static Float PREVOZ;
    public static Float PAUSALNO;
    public static Float UKUPNO;
    public static String NAPOMENA;
    private javax.swing.JLabel brojsati;
    private javax.swing.JLabel datum;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    public javax.swing.JButton jButton5;
    private javax.swing.JInternalFrame jInternalFrame1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel napomena;
    private javax.swing.JLabel pausalno;
    private javax.swing.JLabel porotnik;
    private javax.swing.JLabel posatu;
    private javax.swing.JLabel prevoz;
    public javax.swing.JLabel subroj;
    private javax.swing.JLabel sudija;
    private javax.swing.JTextField filterText;
    private javax.swing.JTable table;
    private  TableRowSorter<MyTableModel> sorter;

    public TableFromDatabase() {

        java.net.URL url2 = ClassLoader.getSystemResource("com/webmarmun/camera.png");
        Toolkit kit = Toolkit.getDefaultToolkit();
        Image img = kit.createImage(url2);
        this.setIconImage(img);


        Vector columnNames = new Vector();
        Vector data = new Vector();

        try {
            //  Connect to an Access Database
            String serverName = "localhost";
            String mydatabase = "porotnici";
            String url = "jdbc:mysql://" + serverName + "/" + mydatabase + "?useUnicode=true&characterEncoding=utf8";
            String userid = "root";
            String password = "";



            java.sql.Connection connection = null;
            connection = DriverManager.getConnection(url, userid, password);

            java.sql.PreparedStatement stmt = connection.prepareStatement("SELECT id,datum,ime_porotnika,ime_sudije,broj_sati,po_satu,prevoz,ukupno,napomena from evidencija");

            ResultSet rs = stmt.executeQuery();
            ResultSetMetaData md = rs.getMetaData();
            int columns = md.getColumnCount();

            //  Get column names

            for (int i = 1; i <= columns; i++) {
                columnNames.addElement(md.getColumnName(i));
            }

            //  Get row data

            while (rs.next()) {
                Vector row = new Vector(columns);

                for (int i = 1; i <= columns; i++) {

                    row.addElement(rs.getObject(i));
                }

                data.addElement(row);
            }

            rs.close();
            stmt.close();
            connection.close();
        } catch (Exception e) {
            System.out.println(e);
        }

        //  Create table with database data

        final JTable table = new javax.swing.JTable(data, columnNames) {

            @Override
            public Class getColumnClass(int column) {
                for (int row = 0; row < getRowCount(); row++) {
                    Object o = getValueAt(row, column);

                    if (o != null) {
                        return o.getClass();
                    }
                }

                return Object.class;
            }
        };
        table.setRowHeight(25);

       
        // JScrollPane scrollPane = new JScrollPane( table );

        // getContentPane().add( scrollPane );

        // JPanel buttonPanel = new JPanel();
        // getContentPane().add( buttonPanel, BorderLayout.SOUTH );


        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();

        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jInternalFrame1 = new javax.swing.JInternalFrame();
        brojsati = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        pausalno = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        datum = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        porotnik = new javax.swing.JLabel();
        datum = new javax.swing.JLabel();
        prevoz = new javax.swing.JLabel();
        subroj = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        posatu = new javax.swing.JLabel();
        sudija = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        napomena = new javax.swing.JLabel();
        jButton5 = new javax.swing.JButton();
        filterText = new javax.swing.JTextField();
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Први основни суд у Београду - Евиденција поротника");


        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jScrollPane1.setViewportView(table);
        jPanel1.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 899, 380));

        jButton1.setText("ШТАМПА ПРВОГ ДЕЛА");
        jButton1.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }

            private void jButton1ActionPerformed(ActionEvent evt) {
                throw new UnsupportedOperationException("Not yet implemented");
            }
        });
        jPanel1.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(690, 470, 200, 60));

        jButton2.setBackground(new java.awt.Color(255, 51, 51));
        jButton2.setForeground(new java.awt.Color(255, 255, 255));
        jButton2.setText("ШТАМПА КОНАЧНО");
        jButton2.setMaximumSize(new java.awt.Dimension(145, 23));
        jButton2.setMinimumSize(new java.awt.Dimension(145, 23));
        jButton2.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(690, 550, 200, 60));

        jButton3.setBackground(new java.awt.Color(0, 153, 255));
        jButton3.setText("Измена");
        jButton3.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(610, 390, 130, 50));

        // jPanel1.add(filterText, new org.netbeans.lib.awtextra.AbsoluteConstraints(610, 460, 150, 30));
        jButton4.setBackground(new java.awt.Color(102, 255, 153));
        jButton4.setText("Додавање");
        jButton4.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton4, new org.netbeans.lib.awtextra.AbsoluteConstraints(760, 390, 130, 50));

        jInternalFrame1.setBorder(null);
        jInternalFrame1.setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        jInternalFrame1.setTitle("Изабрано решење");
        jInternalFrame1.setMaximumSize(new java.awt.Dimension(600, 500));
        jInternalFrame1.setVisible(true);

         brojsati.setText("jLabel11");

        jLabel6.setText("СУ број:");

        jLabel19.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel19.setText("jLabel19");

        jLabel3.setText("Судија:");

        jLabel8.setText("Датум:");

        pausalno.setText("jLabel17");

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel5.setText("Изабрано решење:");

       // datum.setText("jLabel9");

        jLabel16.setText("Паушално:");

        jLabel14.setText("Превоз:");

        jLabel10.setText("Број сати:");

        jLabel18.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel18.setText("Укупно:");

        jLabel2.setText("Поротник:");

        porotnik.setText("jLabel1");

        prevoz.setText("jLabel15");

        subroj.setText("jLabel7");

        jLabel12.setText("Цена по сату:");

        posatu.setText("jLabel13");

        sudija.setText("jLabel4");

        jLabel1.setText("Напомена:");

        filterText.setText("Претрага по датуму");

        napomena.setText("jLabel7");

        javax.swing.GroupLayout jInternalFrame1Layout = new javax.swing.GroupLayout(jInternalFrame1.getContentPane());
        jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout);
        jInternalFrame1Layout.setHorizontalGroup(
                jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jInternalFrame1Layout.createSequentialGroup().addContainerGap().addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jInternalFrame1Layout.createSequentialGroup().addGap(2, 2, 2).addComponent(jLabel8).addGap(81, 81, 81).addComponent(datum)).addGroup(jInternalFrame1Layout.createSequentialGroup().addComponent(jLabel10).addGap(69, 69, 69).addComponent(brojsati)).addGroup(jInternalFrame1Layout.createSequentialGroup().addComponent(jLabel12).addGap(49, 49, 49).addComponent(posatu)).addGroup(jInternalFrame1Layout.createSequentialGroup().addComponent(jLabel14).addGap(80, 80, 80).addComponent(prevoz)).addGroup(jInternalFrame1Layout.createSequentialGroup().addComponent(jLabel16).addGap(65, 65, 65).addComponent(pausalno)).addGroup(jInternalFrame1Layout.createSequentialGroup().addGap(2, 2, 2).addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel5).addGroup(jInternalFrame1Layout.createSequentialGroup().addComponent(jLabel2).addGap(64, 64, 64).addComponent(porotnik)).addGroup(jInternalFrame1Layout.createSequentialGroup().addComponent(jLabel3).addGap(78, 78, 78).addComponent(sudija)).addGroup(jInternalFrame1Layout.createSequentialGroup().addComponent(jLabel6).addGap(75, 75, 75).addComponent(subroj)))).addGroup(jInternalFrame1Layout.createSequentialGroup().addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel1).addComponent(jLabel18)).addGap(67, 67, 67).addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(napomena).addComponent(jLabel19)))).addContainerGap(229, Short.MAX_VALUE)));
        jInternalFrame1Layout.setVerticalGroup(
                jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jInternalFrame1Layout.createSequentialGroup().addContainerGap().addComponent(jLabel5).addGap(6, 6, 6).addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel2).addComponent(porotnik)).addGap(5, 5, 5).addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel3).addComponent(sudija)).addGap(6, 6, 6).addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel6).addComponent(subroj)).addGap(6, 6, 6).addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel8).addComponent(datum)).addGap(7, 7, 7).addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel10).addComponent(brojsati)).addGap(6, 6, 6).addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel12).addComponent(posatu)).addGap(6, 6, 6).addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel14).addComponent(prevoz)).addGap(6, 6, 6).addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jInternalFrame1Layout.createSequentialGroup().addGap(2, 2, 2).addComponent(jLabel16)).addComponent(pausalno)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel1).addComponent(napomena)).addGap(18, 18, 18).addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel19).addComponent(jLabel18)).addGap(56, 56, 56)));

        jPanel1.add(jInternalFrame1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 390, 410, 330));

        jButton5.setText("Освежи табелу");
        jButton5.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }

            private void jButton5ActionPerformed(ActionEvent evt) {
                throw new UnsupportedOperationException("Not yet implemented");
            }
        });
        jPanel1.add(jButton5, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 390, -1, 44));







        // bindingGroup.bind();

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width - 947) / 2, (screenSize.height - 775) / 2, 947, 775);
         getContentPane().add(jPanel1);


        filterText.addMouseListener(
                new MouseListener() {

                    public void mouseClicked(MouseEvent e) {
                        filterText.setText("");

                    }

                    public void mousePressed(MouseEvent e) {
                        filterText.setText("");
                         MyTableModel model = new MyTableModel();
        sorter = new TableRowSorter<MyTableModel>(model);

        table.setRowSorter(sorter);
                    }

                    public void mouseReleased(MouseEvent e) {
                        filterText.setText("");
                    }

                    public void mouseEntered(MouseEvent e) {
                      //  filterText.setText("");
                    }

                    public void mouseExited(MouseEvent e) {
                    }
                });



        JMenuBar menuBar = new JMenuBar();

        // Add the menubar to the frame
        setJMenuBar(menuBar);

        // Define and add two drop down menu to the menubar
        JMenu fileMenu = new JMenu("Додавање поротника");
        JMenu editMenu = new JMenu("Додавање судија");
        JMenu cene = new JMenu("Измена цена");
        JMenu izvestaji = new JMenu("Креирање извештаја");
        JMenu izmenaPorotnika = new JMenu("Измена поротника");
        JMenu izmenaSudije = new JMenu("Измена судије");


        menuBar.add(fileMenu);
        menuBar.add(izmenaPorotnika);
        menuBar.add(editMenu);
        menuBar.add(izmenaSudije);
        menuBar.add(cene);
        menuBar.add(izvestaji);
        menuBar.add(filterText);

        jLabel1.setVisible(false);
        jLabel2.setVisible(false);
        jLabel3.setVisible(false);

        jLabel5.setVisible(false);
        jLabel6.setVisible(false);
        jLabel8.setVisible(false);
        jLabel10.setVisible(false);
        jLabel12.setVisible(false);
        jLabel14.setVisible(false);
        jLabel16.setVisible(false);
        jLabel18.setVisible(false);
        porotnik.setVisible(false);
        sudija.setVisible(false);
        subroj.setVisible(false);
        datum.setVisible(false);
        brojsati.setVisible(false);
        posatu.setVisible(false);
        prevoz.setVisible(false);
        pausalno.setVisible(false);
        napomena.setVisible(false);
        jLabel19.setVisible(false);



        fileMenu.addMouseListener(
                new MouseAdapter() {

                    @Override
                    public void mouseClicked(MouseEvent evt) {
                        Porotnik p = new Porotnik();
                        p.setVisible(true);
                    }
                });

        editMenu.addMouseListener(
                new MouseAdapter() {

                    @Override
                    public void mouseClicked(MouseEvent evt) {
                        Sudija s = new Sudija();
                        s.setVisible(true);
                    }
                });

        cene.addMouseListener(
                new MouseAdapter() {

                    @Override
                    public void mouseClicked(MouseEvent evt) {
                        Cene c = new Cene();
                        c.setVisible(true);
                    }
                });

        izvestaji.addMouseListener(
                new MouseAdapter() {

                    @Override
                    public void mouseClicked(MouseEvent evt) {
                        Reports c = new Reports();
                        c.setVisible(true);
                    }
                });

        izmenaPorotnika.addMouseListener(
                new MouseAdapter() {

                    @Override
                    public void mouseClicked(MouseEvent evt) {
                        IzmenaPorotnika ip = new IzmenaPorotnika();
                        ip.setVisible(true);
                    }
                });
        izmenaSudije.addMouseListener(
                new MouseAdapter() {

                    @Override
                    public void mouseClicked(MouseEvent evt) {
                        IzmenaSudije is = new IzmenaSudije();
                        is.setVisible(true);
                    }
                });
               
             table.addMouseListener( new MouseAdapter() {



            @Override
                    public void mouseClicked(MouseEvent evt) {
                        
                        int col = table.getSelectedColumn();
                        int row = table.getSelectedRow();
                         
                        jLabel1.setVisible(true);
                        jLabel2.setVisible(true);
                        jLabel3.setVisible(true);

                        jLabel6.setVisible(true);
                        jLabel8.setVisible(true);
                        jLabel10.setVisible(true);
                        jLabel12.setVisible(true);
                        jLabel14.setVisible(true);
                        jLabel16.setVisible(true);
                        jLabel18.setVisible(true);
                        porotnik.setVisible(true);
                        napomena.setVisible(true);
                        sudija.setVisible(true);
                        subroj.setVisible(true);
                        datum.setVisible(true);
                        datum.setText(table.getValueAt(row, 1).toString());
                        brojsati.setVisible(true);
                         brojsati.setText(table.getValueAt(row, 4).toString());
                        posatu.setVisible(true);
                        posatu.setText(table.getValueAt(row, 5).toString());
                        prevoz.setVisible(true);
                         prevoz.setText(table.getValueAt(row, 6).toString());
                       // pausalno.setVisible(true);
                        // pausalno.setText(table.getValueAt(row, 7).toString());
                        jLabel19.setVisible(true);
                        jLabel19.setText(table.getValueAt(row, 7).toString());
                        porotnik.setText(table.getValueAt(row, 2).toString());

                        sudija.setText(table.getValueAt(row, 3).toString());
                        subroj.setText(table.getValueAt(row, 0).toString());
                        napomena.setText(table.getValueAt(row, 8).toString());
                        
                       
                       
                        
                       
                       
                        int brojsati = Integer.parseInt(table.getValueAt(row, 4).toString());
                        Float radnisat = new Float(table.getValueAt(row, 5).toString());
                        Float prevoz = new Float(table.getValueAt(row, 6).toString());
                        Float pausalno = new Float(table.getValueAt(row, 7).toString());
                        Float ukupno = (brojsati * radnisat) + prevoz; //+pausalno;
                       // table.setValueAt(ukupno, row, 8);
                       // sveZajedno = Float.toString(ukupno);
                        //jLabel19.setText(sveZajedno);

                        SU = subroj.getText();
                        DATUM = datum.getText();
                        POROTNIK = porotnik.getText();
                        SUDIJA = sudija.getText();
                        MESTO = "Београд";
                        RADNISAT = radnisat;
                        BROJSATI = brojsati;
                        PREVOZ = prevoz;
                        PAUSALNO = new Float(0);
                        UKUPNO = ukupno;
                        NAPOMENA = napomena.getText();





                    }
                });
        
       
       
        
    }

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {


        BufferedImage bi;
        Font font = new Font("Arial", Font.PLAIN, 25);
        Component frame1 = null;
        try {

            bi = ImageIO.read(new File("zahtev.jpg"));
            Graphics2D g2 = bi.createGraphics();
            g2.setColor(Color.black);
            g2.setFont(font);
            g2.drawString(datum.getText(), 750, 255);
            g2.drawString(porotnik.getText(), 520, 518);
            g2.drawString(datum.getText(), 330, 547);
            g2.drawString(subroj.getText(), 300, 842);
            g2.drawString(datum.getText(), 430, 842);


            File outputfile = new File("prvi_deo_resenja/" + POROTNIK + DATUM + ".jpg");



            ImageIO.write(bi, "jpg", outputfile);
            PrintImage p = new PrintImage();
            try {
                p.print(outputfile.getPath(), 1);
            } catch (Exception ex) {
                Logger.getLogger(FirstFrame.class.getName()).log(Level.SEVERE, null, ex);
            }

        } catch (IOException ex) {
            Logger.getLogger(FirstFrame.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(frame1,
                    "Грешка код читања документа !\n" + ex.toString(),
                    "Први основни суд у Београду",
                    JOptionPane.WARNING_MESSAGE);
        }




    }

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
        BufferedImage bi;
        Font font = new Font("Arial", Font.PLAIN, 25);
        Component frame1 = null;
        try {

            bi = ImageIO.read(new File("empty.png"));
            Graphics2D g2 = bi.createGraphics();
            g2.setColor(Color.black);
            g2.setFont(font);
          
            g2.drawString(porotnik.getText(), 440, 1030);
            g2.drawString("Београд", 950, 1030);
            g2.drawString(datum.getText(), 640, 1060);
            g2.drawString(prevoz.getText(), 830, 1108);
            g2.drawString("0,0", 830, 1143);
            g2.drawString(pausalno.getText(), 830, 1180);
            g2.drawString(posatu.getText(), 830, 1217);
            g2.drawString(sveZajedno, 830, 1255);

            File outputfile = new File("resenja/" + POROTNIK + DATUM + ".jpg");
            ImageIO.write(bi, "jpg", outputfile);
            PrintImage p = new PrintImage();
            try {
                p.print("resenja/" + POROTNIK + DATUM + ".jpg", 1);
            } catch (Exception ex) {
                Logger.getLogger(FirstFrame.class.getName()).log(Level.SEVERE, null, ex);
                JOptionPane.showMessageDialog(frame1,
                        "Грешка код штампања документа !\n" + ex.toString(),
                        "Први основни суд у Београду",
                        JOptionPane.WARNING_MESSAGE);
            }

        } catch (IOException ex) {
            Logger.getLogger(FirstFrame.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(frame1,
                    "Грешка код читања документа !\n" + ex.toString(),
                    "Први основни суд у Београду",
                    JOptionPane.WARNING_MESSAGE);
        }


    }

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
        Component frame2 = null;
        if (subroj.isShowing()) {
            Izmena i = new Izmena();
            i.setVisible(true);
            dispose();
        } else {
            JOptionPane.showMessageDialog(frame2,
                    "Морате изабрати неко од решења за измену !",
                    "Први основни суд у Београду",
                    JOptionPane.WARNING_MESSAGE);
        }
    }

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {

    }

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
        Dodavanje d = new Dodavanje();
        d.setVisible(true);
        dispose();
    }

    public class PrintImage {

        public void print(String s, int i) throws Exception {
            Component frame = null;
            try {
                PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
                pras.add(MediaSize.findMedia(10, 10, Size2DSyntax.MM));
                pras.add(new Copies(i));

                PrintService pss[] = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.JPEG, pras);

                if (pss.length == 0) {
                    // throw new RuntimeException("Штампач није пронађен.");
                    JOptionPane.showMessageDialog(frame,
                            "Штампач није пронађен !",
                            "Први основни суд у Београду",
                            JOptionPane.WARNING_MESSAGE);
                }

                PrintService ps = pss[0];


                DocPrintJob job = ps.createPrintJob();

                FileInputStream fin = new FileInputStream(s);
                Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.JPEG, null);

                job.print(doc, pras);

                fin.close();
            } catch (IOException ie) {
                JOptionPane.showMessageDialog(frame,
                        "Грешка код штампања !/n" + ie.toString(),
                        "Први основни суд у Београду",
                        JOptionPane.WARNING_MESSAGE);
            } catch (PrintException pe) {
                JOptionPane.showMessageDialog(frame,
                        "Грешка код штампања !/n" + pe.toString(),
                        "Први основни суд у Београду",
                        JOptionPane.WARNING_MESSAGE);
            }
        }
    }

    public static void main(String[] args) {
//        TableFromDatabase frame = new TableFromDatabase();
//        frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
//
//        frame.setTitle("Први основни суд у Београду - Поротници");
//        frame.pack();
//        frame.setVisible(true);
        new TableFromDatabase().setVisible(true);
    }


    private void newFilter() {
        RowFilter<MyTableModel, Object> rf = null;
        //If current expression doesn't parse, don't update.
        try {

            rf = RowFilter.regexFilter(filterText.getText(), 0);
        } catch (java.util.regex.PatternSyntaxException e) {
            return;
        }
        sorter.setRowFilter(rf);
    }

    class MyTableModel extends AbstractTableModel {
        private Object[][] data;

        public int getColumnCount() {
            return table.getColumnCount();
        }

        public int getRowCount() {
            return table.getRowCount();
        }

        @Override
        public String getColumnName(int col) {
            return table.getColumnName(col);
        }

        public Object getValueAt(int row, int col) {
            return table.getValueAt(row, col);
        }

        @Override
         public void setValueAt(Object value, int row, int col) {
        data[row][col] = value;
        fireTableCellUpdated(row, col);
    }
    }

}
